package com.crmweb.controller;

import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crmweb.dto.TreeModules;
import com.crmweb.entity.Users;
import com.crmweb.service.UsersService;
import com.crmweb.tool.ConstantUtil;

@Controller
public class UserTreeController {
	@Resource
	private UsersService us;
	@RequestMapping("/dsds")
	public Object seldsds() {
		return "login";
	}
	
//	//查询树
	@RequestMapping("/queryTree")
	@ResponseBody
	public Object queryTree(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		HttpSession session=request.getSession(); 
		Users users=(Users)session.getAttribute(ConstantUtil.USERS);
	//	System.out.println(users+"-------------------------------");
		//return "login";
		//response.sendRedirect("classpath:login.html");
//		if(users ==null) {
//			System.out.println("页面跳转");
//		response.sendRedirect("classpath:login.html");
//		
//			
//		//	return "login";
//		}else {
//			List<TreeModules> list=us.queryModulesTreeNodes(users);
//			List<TreeModules> nodes=us.queryModel(list);
//			return nodes;
//		}
//		return null;
		if(users !=null) {
			List<TreeModules> list=us.queryModulesTreeNodes(users);
			List<TreeModules> nodes=us.queryModel(list);
			System.out.println(nodes.size());
			return nodes;
		}else {
			//response.sendRedirect("classpath:login.html");
			List<Integer> list= new ArrayList<>();
			list.add(1);
			return list;
		}
	

		
	}
}
